/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { ModuleBuildProfile } from '../build/module-build-profile.js';
import { Named, Option, RequiredNamed } from '../options';

import { AppEnvironmentOption } from './app_environment_option.js';
import AppEnvironmentObj = AppEnvironmentOption.AppEnvironmentObj;

export namespace ConfigJson {
  export interface AppObj extends Option {
    bundleName: string;
    vendor?: string;
    apiVersion?: ApiVersionObj;
    version: VersionObj;
    type?: string;
    targetBundleList?: string[];
    relatedBundleName?: string;
    smartWindowSize?: string;
    smartWindowDeviceType?: string[];
    singleton?: boolean;
    removable?: boolean;
    userDataClearable?: boolean;
    asanEnabled?: boolean;
    tsanEnabled?: boolean;
    hwasanEnabled?: boolean;
    ubsanEnabled?: boolean;
    appEnvironments?: AppEnvironmentObj[];
  }

  export interface ApiVersionObj extends Option {
    compatible?: number;
    target?: number;
    releaseType?: string;
  }

  export interface VersionObj extends Named {
    code: number;
    minCompatibleVersionCode?: number;
  }

  export interface DeviceConfigObj extends Option {
    [propName: string]: DeviceConfigOptionObj;
  }

  export interface DeviceConfigOptionObj extends Option {
    jointUserId?: string;
    process?: string;
    ark?: ArkObj;
    keepAlive?: boolean;
    directLaunch?: boolean;
    network?: NetworkObj;
    supportBackup?: boolean;
    compressNativeLibs?: boolean;
    allowComponentsProxy?: boolean;
    debug?: boolean;
  }

  export interface ArkObj extends Option {
    reqVersion?: ReqVersionObj;
    flag?: string;
  }

  export interface ReqVersionObj extends Option {
    compatible?: number;
    target?: number;
  }

  export interface NetworkObj extends Option {
    cleartextTraffic?: boolean;
    securityConfig?: SecurityConfigObj;
  }

  export interface SecurityConfigObj extends Option {
    domainSettings: DomainSettingsObj;
  }

  export interface DomainSettingsObj extends Option {
    cleartextPermitted: boolean;
    domains: DomainObj[];
  }

  export interface DomainObj extends Named {
    subdomains?: boolean;
  }

  export interface ModuleObj extends RequiredNamed {
    package: string;
    description?: string;
    supportedModes?: string[];
    theme?: string;
    entryTheme?: string;
    reqCapabilities?: string[];
    deviceType: string[];
    distro: DistroObj;
    metaData?: MetaDataObj;
    abilities?: AbilitiesObj[];
    commonEvents?: CommonEventObj[];
    shortcuts?: ShortcutsObj[];
    js?: JsObj[];
    reqPermissions?: ReqPermissionsObj[];
    defPermissions?: DefPermissionsObj[];
    definePermissions?: DefPermissionsObj[];
    defPermissionGroups?: DefPermissionGroupsObj[];
    allowClassMap?: boolean;
    mainAbility?: string;
    resizeable?: boolean;
    colorMode?: string;
    testRunner?: TestRunnerObj;
    distroFilter?: ModuleBuildProfile.DistroFilterBuildOpt;
  }

  export interface TestRunnerObj extends RequiredNamed {
    srcPath: string;
  }

  export interface DistroObj extends Option {
    deliveryWithInstall: boolean;
    moduleName: string;
    moduleType: string;
    installationFree?: boolean;
  }

  export interface MetaDataObj extends Option {
    parameters?: ParametersObj[];
    results?: ResultObj[];
    customizeData?: CustomizeDataObj[];
    mergeRule?: MergeRuleObj;
  }

  export interface ParametersObj extends Named {
    type: string;
    description?: string;
    mergeRule?: MergeRuleObj;
  }

  export interface ResultObj extends Named {
    type: string;
    description?: string;
    mergeRule?: MergeRuleObj;
  }

  export interface CustomizeDataObj extends Named {
    value?: string;
    extra?: string;
    mergeRule?: MergeRuleObj;
  }

  export interface AbilitiesObj extends RequiredNamed {
    description?: string;
    icon?: string;
    label?: string;
    skills?: SkillsObj[];
    orientation?: string;
    visible?: boolean;
    srcPath: string;
    srcLanguage?: string;
    formsEnabled?: boolean;
    type: string;
    launchType?: string;
    theme?: string;
    uri?: string;
    metaData?: MetaDataObj;
    permissions?: string[];
    configChanges?: string[];
    process?: string;
    backgroundModes?: string[];
    grantPermission?: boolean;
    definePermissions?: DefinePermissionsObj;
    formEnabled?: boolean;
    form?: FormObj;
    readPermission?: string;
    writePermission?: string;
    uriPermission?: UriPermissionObj;
    multiUserShared?: boolean;
    mission?: string;
    targetAbility?: string;
    supportPipMode?: boolean;
    mergeRule?: MergeRuleObj;
    forms?: FormsObj[];
    resizeable?: boolean;
    deviceCapability?: string[];
    entryTheme?: string;
  }

  export interface SkillsObj extends Option {
    actions?: string[];
    entities?: string[];
    uris?: UrisObj[];
  }

  export interface UrisObj extends Option {
    scheme?: string;
    host?: string;
    port?: string;
    path?: string;
    pathStartWith?: string;
    pathRegx?: string;
    type?: string;
    uri?: string;
  }

  export interface FormObj extends Option {
    formEntity: string[];
    minHeight: number;
    defaultHeight: number;
    minWidth: number;
    defaultWidth: number;
  }

  export interface FormsObj extends RequiredNamed {
    description?: string;
    type?: string;
    jsComponentName?: string;
    colorMode?: string;
    isDefault?: string;
    updateEnabled?: boolean;
    scheduledUpdateTime?: number;
    updateDuration?: number;
    supportDimensions?: string[];
    defaultDimension?: string;
    landscapeLayouts?: string[];
    portraitLayouts?: string[];
    deepLink?: string;
    metaData?: MetaDataObj[];
    formConfigAbility?: string;
    formVisibleNotify?: boolean;
  }

  export interface UriPermissionObj extends Option {
    mode?: string;
    path: string;
  }

  export interface CommonEventObj extends Named {
    permission?: string;
    data?: string[];
    type?: string[];
    events: string[];
    mergeRule?: MergeRuleObj;
  }

  export interface ShortcutsObj extends Option {
    shortcutId?: string;
    label?: string;
    icon?: string;
    intents?: IntentObj[];
  }

  export interface IntentObj extends Option {
    targetClass?: string;
    targetBundle?: string;
  }

  export interface JsObj extends RequiredNamed {
    pages: string[];
    window?: WindowObj;
    mergeRule?: MergeRuleObj;
    type?: string;
    mode?: ModeObj;
  }

  export interface WindowObj extends Option {
    designWidth?: number;
    autoDesignWidth?: boolean;
  }

  export interface ModeObj extends Option {
    syntax?: string;
    type?: string;
  }

  export interface ReqPermissionsObj extends RequiredNamed {
    reason?: string;
    usedScene?: UsedSceneObj;
    mergeRule?: MergeRuleObj;
  }

  export interface UsedSceneObj extends Option {
    ability?: string[];
    when?: string;
  }

  export interface DefPermissionsObj extends Named {
    grantMode?: string;
    label?: string;
    description?: string;
    group?: string;
    availableScope?: string[];
    mergeRule?: MergeRuleObj;
  }

  export interface DefinePermissionsObj extends Named {
    grantMode?: string;
    label?: string;
    description?: string;
    availableLevel?: string;
    provisionEnable?: boolean;
    distributedSceneEnable?: boolean;
  }

  export interface DefPermissionGroupsObj extends Named {
    icon?: string;
    label?: string;
    description?: string;
    order?: number;
    request?: string;
    mergeRule?: MergeRuleObj;
  }

  export interface MergeRuleObj extends Option {
    remove?: string[];
    replace?: string[];
  }

  export interface ConfigOptObj extends Option {
    app: AppObj;
    deviceConfig: DeviceConfigObj;
    module: ModuleObj;
  }
}
